using System;
using System.ComponentModel;
using System.Collections.Generic;

namespace shfa.snomtastic.data.business
{
	[DataObject(true)]
    public partial class UserController
    {
	
		public SqlDataProvider DataProvider { get; set; }

        public UserController()
        {
            DataProvider = new SqlDataProvider();
        }
	
		[DataObjectMethod(DataObjectMethodType.Insert, true)]
        public Guid InsertUser(UserInfo oi)
		{
            return DataProvider.InsertUser(oi.GroupId, oi.UserName, oi.Password, oi.PasswordUpdate, oi.PasswordUpdateAD, oi.CreatedDate, oi.UpdatedDate, oi.LastAccessDate);
		}

		[DataObjectMethod(DataObjectMethodType.Update, true)]
        public int UpdateUser(UserInfo oi) 
		{
			return DataProvider.UpdateUser(oi.UserId, oi.GroupId, oi.UserName, oi.Password, oi.PasswordUpdate, oi.PasswordUpdateAD, oi.CreatedDate, oi.UpdatedDate, oi.LastAccessDate);
		}
		
		[DataObjectMethod(DataObjectMethodType.Delete, true)]
        public int DeleteUser(Guid userId)
		{
			return DataProvider.DeleteUser(userId);
        }

		[DataObjectMethod(DataObjectMethodType.Select, true)]
        public UserInfo SelectUser(Guid userId)
        {    
			return ObjectFromDataRow(DataProvider.SelectUser(userId));
        }
		
		[DataObjectMethod(DataObjectMethodType.Select, true)]
        public List<UserInfo> SelectUsers()
		{
            return ListFromDataTable(DataProvider.SelectUsers());
        }
		
		[DataObjectMethod(DataObjectMethodType.Select, true)]
        public List<UserInfo> SelectUsers(string sortExpression)
        {
            List<UserInfo> retList = SelectUsers();
            if (sortExpression.Length > 0)
            {
                retList.Sort(new UserComparer(sortExpression));
            }
            return retList;
        }

        [DataObjectMethod(DataObjectMethodType.Select, true)]
		public List<UserInfo> SelectUsersByGroup(Guid groupId)
		{
			return ListFromDataTable(DataProvider.SelectUsersByGroup(groupId));
		}
		
        public List<UserInfo> SelectUsersByGroup(Guid groupId,string sortExpression)
		{
			List<UserInfo> retList = SelectUsersByGroup(groupId);
            if (sortExpression.Length > 0)
            {
                retList.Sort(new UserComparer(sortExpression));
            }
            return retList;
		}

	}

}
		